package ius.mantianx.handler;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author starrysky
 * @title: ThyInterceptor
 * @projectName rev_thymeleaf_boot
 * @description: Interceptor layer
 * @date 2021/2/812:17
 */
public class ThyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object loginUser = request.getSession().getAttribute("loginUser");
        System.out.println(loginUser);
        if (loginUser==null){
            request.setAttribute("msg","未登录，没有权限访问！");
            request.getRequestDispatcher("/login").forward(request,response);
            return false;
        }else {
            return true;
        }

    }
}
